package utils

import (
	"strconv"
)

func StringToByte(tStr string) byte {
	tValue, _ := strconv.Atoi(tStr)
	return byte(tValue)
}

func StringToInt8(tStr string) int8 {
	tValue, _ := strconv.Atoi(tStr)
	return int8(tValue)
}
func StringToUint8(tStr string) uint8 {
	tValue, _ := strconv.Atoi(tStr)
	return uint8(tValue)
}

func StringToInt(tStr string) int {
	tValue, _ := strconv.Atoi(tStr)
	return int(tValue)
}

func StringToInt32(tStr string) int32 {
	tValue, _ := strconv.Atoi(tStr)
	return int32(tValue)
}

func StringToUint32(tStr string) uint32 {
	tValue, _ := strconv.Atoi(tStr)
	return uint32(tValue)
}

func StringToInt64(tStr string) int64 {
	tValue, _ := strconv.ParseInt(tStr, 10, 64)
	return tValue
}
func StringToUint64(tStr string) uint64 {
	tValue, _ := strconv.ParseInt(tStr, 10, 64)
	return uint64(tValue)
}

func StringToInt16(tStr string) int16 {
	tValue, _ := strconv.Atoi(tStr)
	return int16(tValue)
}

func StringToUint16(tStr string) uint16 {
	tValue, _ := strconv.Atoi(tStr)
	return uint16(tValue)
}

func StrToInt(s string, defaultVal ...int) int {
	if s == "" && len(defaultVal) > 0 {
		return defaultVal[0]
	}
	if v, e := strconv.Atoi(s); e == nil {
		return v
	} else {
		return 0
	}
}

func StrToUint64(s string) uint64 {
	num, err := strconv.ParseUint(s, 10, 64)
	if err != nil {
		return 0
	} else {
		return num
	}
}
